home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JRootPane.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  26.1 KB  |  702 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JRootPane.java    1.37 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package javax.swing;
  15.  
  16. import java.awt.*;
  17. import java.awt.event.*;
  18. import javax.accessibility.*;
  19. import java.util.Vector;
  20. import java.io.Serializable;
  21.  
  22.  
  23. /** 
  24.  * The fundamental component in the container hierarchy. In the same way that
  25.  * JComponent is fundamental to the JFC/Swing components, JRootPane is fundamental
  26.  * to the JFC/Swing window, frame, and pane containers.
  27.  * However, while other classes use inheritance to take advantage of JComponent's
  28.  * capabilities, the container classes delegate operations to a JRootPane instance.
  29.  * Those containers are the heavyweight containers: JFrame, JDialog, JWindow, and 
  30.  * JApplet, as well as the lightweight container, JInternalFrame.
  31.  * <p>
  32.  * The following image shows these relationships:
  33.  * <p align=center><img src="doc-files/JRootPane-1.gif" HEIGHT=484 WIDTH=629></p>
  34.  * The "heavyweight" components (those that delegate to a peer, or native
  35.  * component on the host system) are shown with a darker, heavier box. The four
  36.  * heavyweight JFC/Swing containers (JFrame, JDialog, JWindow, and JApplet) are 
  37.  * shown in relation to the AWT classes they extend. These four components are the
  38.  * only heavyweight containers in the Swing library. The lightweight container, 
  39.  * JInternalPane, is also shown. All 5 of these JFC/Swing containers implement the
  40.  * RootPaneContainer interface, and they all delegate their operations to a 
  41.  * JRootPane (shown with a little "handle" on top).
  42.  * <blockquote>
  43.  * <b>Note:</b> The JComponent method <code>getRootPane</code> can be used to
  44.  * obtain the JRootPane that contains a given component.  
  45.  * </blockquote>
  46.  * <table align="right" border="0">
  47.  * <tr>
  48.  * <td align="center">
  49.  * <img src="doc-files/JRootPane-2.gif" HEIGHT=386 WIDTH=349>
  50.  * </td>
  51.  * </tr>
  52.  * </table>
  53.  * The diagram at right shows the structure of a JRootPane.
  54.  * A JRootpane is made up of a glassPane, an optional menuBar, and
  55.  * a contentPane. (The JLayeredPane manages the menuBar and the contentPane.)
  56.  * The glassPane sits over the top of everything, where it is in a position
  57.  * to intercept mouse movements. Since the glassPane (like the contentPane)
  58.  * can be an arbitrary component, it is also possible to set up the 
  59.  * glassPane for drawing. Lines and images on the glassPane can then range
  60.  * over the frames underneath without being limited by their boundaries. 
  61.  * <p>
  62.  * Although the menuBar component is optional, the layeredPane, contentPane,
  63.  * and glassPane always exist. Attempting to set them to null generates an
  64.  * exception. 
  65.  * <p>
  66.  * The <code>contentPane</code> must be the parent of any children of 
  67.  * the JRootPane. Rather than adding directly to a JRootPane, like this:
  68.  * <PRE>
  69.  *       rootPane.add(child);
  70.  * </PRE>
  71.  * You instead add to the contentPane of the JRootPane, like this:
  72.  * <PRE>
  73.  *       rootPane.getContentPane().add(child);
  74.  * </PRE>
  75.  * The same priniciple holds true for setting layout managers, removing 
  76.  * components, listing children, etc. All these methods are invoked on  
  77.  * the <code>contentPane</code> instead of on the JRootPane.
  78.  * <blockquote>
  79.  * <b>Note:</b> The default layout manager for the <code>contentPane</code> is
  80.  *  a BorderLayout manager. However, the JRootPane uses a custom LayoutManager.
  81.  *  So, when you want to change the layout manager for the components you added
  82.  *  to a JRootPane, be sure to use code like this:<PRE>
  83.  *    rootPane.getContentPane().setLayout(new BoxLayout());
  84.  * </PRE></blockquote>
  85.  * If a JMenuBar component is set on the JRootPane, it is positioned 
  86.  * along the upper edge of the frame. The <code>contentPane</code> is
  87.  * adjusted in location and size to fill the remaining area. 
  88.  * (The JMenuBar and the <code>contentPane</code> are added to the 
  89.  * <code>layeredPane</code> component at the JLayeredPane.FRAME_CONTENT_LAYER 
  90.  * layer.) 
  91.  * <p>
  92.  * The <code>layeredPane</code> is the parent of all children in the JRootPane.
  93.  * It is an instance of JLayeredPane, which provides the ability to add components 
  94.  * at several layers. This capability is very useful when working with menu popups,
  95.  * dialog boxes, and dragging -- situations in which you need to place a component
  96.  * on top of all other components in the pane.
  97.  * <p>
  98.  * The <code>glassPane</code> sits on top of all other components in the JRootPane.
  99.  * That provides a convenient place to draw above all other components, and makes
  100.  * it possible to intercept mouse events, which is useful both for dragging and
  101.  * for drawing. Developers can use <code>setVisible</code> on the glassPane
  102.  * to control when the <code>glassPane</code> displays over the other children. 
  103.  * By default the <code>glassPane</code> is not visible. 
  104.  * <p>
  105.  * The custom LayoutManager used by JRootPane ensures that:
  106.  * <OL>
  107.  * <LI>The <code>glassPane</code>, if present, fills the entire viewable
  108.  *     area of the JRootPane (bounds - insets).
  109.  * <LI>The <code>layeredPane</code> fills the entire viewable area of the
  110.  *     JRootPane. (bounds - insets)
  111.  * <LI>The <code>menuBar</code> is positioned at the upper edge of the 
  112.  *     layeredPane().
  113.  * <LI>The <code>contentPane</code> fills the entire viewable area, 
  114.  *     minus the MenuBar, if present.
  115.  * </OL>
  116.  * Any other views in the JRootPane view hierarchy are ignored.
  117.  * <p>
  118.  * If you replace the LayoutManager of the JRootPane, you are responsible for 
  119.  * managing all of these views. So ordinarily you will want to be sure that you
  120.  * change the layout manager for the <code>contentPane</code> rather than 
  121.  * for the JRootPane itself!
  122.  * <p>
  123.  * <strong>Warning:</strong>
  124.  * Serialized objects of this class will not be compatible with
  125.  * future Swing releases.  The current serialization support is appropriate
  126.  * for short term storage or RMI between applications running the same
  127.  * version of Swing.  A future release of Swing will provide support for
  128.  * long term persistence.
  129.  *
  130.  * @see JLayeredPane
  131.  * @see JMenuBar
  132.  * @see JWindow
  133.  * @see JFrame
  134.  * @see JDialog
  135.  * @see JApplet
  136.  * @see JInternalFrame
  137.  * @see JComponent
  138.  * @see BoxLayout
  139.  *
  140.  * @see <a href="http://java.sun.com/products/jfc/swingdoc-archive/mixing.html">
  141.  * Mixing Heavy and Light Components</a>
  142.  *
  143.  * @version 1.37 08/28/98
  144.  * @author David Kloba
  145.  */
  146. /// PENDING(klobad) Who should be opaque in this component?
  147. public class JRootPane extends JComponent implements Accessible {
  148.  
  149.     /** The menu bar. */
  150.     protected JMenuBar menuBar;
  151.  
  152.     /** The content pane. */
  153.     protected Container contentPane;
  154.  
  155.     /** The layered pane that manages the menu bar and content pane. */
  156.     protected JLayeredPane layeredPane;
  157.  
  158.     /**
  159.      * The glass pane that overlays the menu bar and content pane,
  160.      *  so it can intercept mouse movements and such.
  161.      */
  162.     protected Component glassPane;
  163.     /** 
  164.      * The button that gets activated when the pane has the focus and
  165.      * a UI-specific action like pressing the Enter key occurs.
  166.      */
  167.     protected JButton defaultButton;
  168.     /** The action to take when the defaultButton is pressed.
  169.      *  @see #defaultButton
  170.      */ 
  171.     protected DefaultAction defaultPressAction;   
  172.     /** The action to take when the defaultButton is released.
  173.      *  @see #defaultButton
  174.      */ 
  175.     protected DefaultAction defaultReleaseAction;
  176.  
  177.     /** 
  178.      * Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane.
  179.      */
  180.     public JRootPane() {
  181.         setGlassPane(createGlassPane());
  182.         setLayeredPane(createLayeredPane());
  183.         setContentPane(createContentPane());
  184.         setLayout(createRootLayout());
  185.         setDoubleBuffered(true);
  186.         setBackground(UIManager.getColor("control"));
  187.     }
  188.  
  189.     /** Called by the constructor methods to create the default layeredPane. 
  190.       * Bt default it creates a new JLayeredPane. 
  191.       */
  192.     protected JLayeredPane createLayeredPane() {
  193.         JLayeredPane p = new JLayeredPane();
  194.         p.setName(this.getName()+".layeredPane");
  195.         return p;
  196.     }
  197.  
  198.     /** Called by the constructor methods to create the default contentPane. 
  199.      * By default this method creates a new JComponent add sets a 
  200.      * BorderLayout as its LayoutManager.
  201.      */
  202.     protected Container createContentPane() {
  203.         JComponent c = new JPanel();
  204.         c.setName(this.getName()+".contentPane");
  205.         c.setLayout(new BorderLayout() {
  206.             /* This BorderLayout subclass maps a null constraint to CENTER.
  207.              * Although the reference BorderLayout also does this, some VMs
  208.              * throw an IllegalArgumentException.
  209.              */
  210.             public void addLayoutComponent(Component comp, Object constraints) {
  211.                 if (constraints == null) {
  212.                     constraints = BorderLayout.CENTER;
  213.                 }
  214.                 super.addLayoutComponent(comp, constraints);
  215.             }
  216.         });
  217.         return c;
  218.     }
  219.  
  220.     /** Called by the constructor methods to create the default glassPane. 
  221.       * By default this method creates a new JComponent with visibility 
  222.       * set to false.
  223.       */
  224.     protected Component createGlassPane() {
  225.         JComponent c = new JPanel();
  226.         c.setName(this.getName()+".glassPane");
  227.         c.setVisible(false);
  228.         ((JPanel)c).setOpaque(false);
  229.         return c;
  230.     }
  231.  
  232.     /** Called by the constructor methods to create the default layoutManager. */
  233.     protected LayoutManager createRootLayout() {
  234.         return new RootLayout();
  235.     } 
  236.  
  237.     /** 
  238.      * Adds or changes the menu bar used in the layered pane. 
  239.      * @param menu the JMenuBar to add
  240.      */
  241.     public void setJMenuBar(JMenuBar menu) {
  242.         if(menuBar != null && menuBar.getParent() == layeredPane)
  243.             layeredPane.remove(menuBar);
  244.         menuBar = menu;
  245.  
  246.         if(menuBar != null)
  247.             layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  248.     }
  249.  
  250.     /**
  251.      * Specifies the menu bar value.
  252.      * @deprecated As of Swing version 1.0.3
  253.      *  replaced by <code>setJMenuBar(JMenuBar menu)</code>.
  254.      */
  255.     public void setMenuBar(JMenuBar menu){
  256.         if(menuBar != null && menuBar.getParent() == layeredPane)
  257.             layeredPane.remove(menuBar);
  258.         menuBar = menu;
  259.  
  260.         if(menuBar != null)
  261.             layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  262.     }
  263.     
  264.     /** 
  265.      * Returns the menu bar from the layered pane. 
  266.      * @return the JMenuBar used in the pane
  267.      */
  268.     public JMenuBar getJMenuBar() { return menuBar; }
  269.  
  270.     /**
  271.      * Returns the menu bar value.
  272.      * @deprecated As of Swing version 1.0.3
  273.      *  replaced by <code>getJMenubar()</code>.
  274.      */
  275.     public JMenuBar getMenuBar() { return menuBar; }
  276.  
  277.     /** 
  278.      * Sets the content pane -- the container that holds the components
  279.      * parented by the root pane.
  280.      *  
  281.      * @param content the Container to use for component-contents
  282.      * @exception java.awt.IllegalComponentStateException (a runtime
  283.      *            exception) if the content pane parameter is null
  284.      */
  285.     public void setContentPane(Container content) {
  286.         if(content == null)
  287.             throw new IllegalComponentStateException("contentPane cannot be set to null.");
  288.         if(contentPane != null && contentPane.getParent() == layeredPane)
  289.             layeredPane.remove(contentPane);
  290.         contentPane = content;
  291.  
  292.         layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
  293.     }
  294.  
  295.     /** 
  296.      * Returns the content pane -- the container that holds the components
  297.      * parented by the root pane.
  298.      *  
  299.      * @return the Container that holds the component-contents
  300.      */
  301.     public Container getContentPane() { return contentPane; }
  302.  
  303. // PENDING(klobad) Should this reparent the contentPane and MenuBar?
  304.     /**
  305.      * Set the layered pane for the root pane. The layered pane
  306.      * typically holds a content pane and an optional JMenuBar.
  307.      *
  308.      * @param layered  the JLayeredPane to use.
  309.      * @exception java.awt.IllegalComponentStateException (a runtime
  310.      *            exception) if the layered pane parameter is null
  311.      */
  312.     public void setLayeredPane(JLayeredPane layered) {
  313.         if(layered == null)
  314.             throw new IllegalComponentStateException("layeredPane cannot be set to null.");
  315.         if(layeredPane != null && layeredPane.getParent() == this)
  316.             this.remove(layeredPane);
  317.         layeredPane = layered;
  318.  
  319.         this.add(layeredPane, -1);
  320.     }
  321.     /**
  322.      * Get the layered pane used by the root pane. The layered pane
  323.      * typically holds a content pane and an optional JMenuBar.
  324.      *
  325.      * @return the JLayeredPane currently in use
  326.      */
  327.     public JLayeredPane getLayeredPane() { return layeredPane; }
  328.  
  329.     /**
  330.      * Sets a specified Component to be the glass pane for this
  331.      * root pane.  The glass pane should normally be a lightweight,
  332.      * transparent component, because it will be made visible when
  333.      * ever the root pane needs to grab input events.  For example,
  334.      * only one JInternalFrame is ever active when using a
  335.      * DefaultDesktop, and any inactive JInternalFrames' glass panes
  336.      * are made visible so that clicking anywhere within an inactive
  337.      * JInternalFrame can activate it.
  338.      * @param glass the Component to use as the glass pane for this
  339.      *              JRootPane.
  340.      */
  341.     public void setGlassPane(Component glass) {
  342.         if (glass == null) {
  343.             throw new NullPointerException("glassPane cannot be set to null.");
  344.         }
  345.  
  346.         boolean visible = false;
  347.         if (glassPane != null && glassPane.getParent() == this) {
  348.             this.remove(glassPane);
  349.             visible = glassPane.isVisible();
  350.         }
  351.  
  352.         glass.setVisible(visible);
  353.         glassPane = glass;
  354.         this.add(glassPane, 0);
  355.         if (visible) {
  356.             repaint();
  357.         }
  358.     }
  359.  
  360.     /**
  361.      * Returns the current glass pane for this JRootPane.
  362.      * @return the current glass pane.
  363.      * @see #setGlassPane
  364.      */
  365.     public Component getGlassPane() { 
  366.         return glassPane; 
  367.     }
  368.  
  369.     /**
  370.      * Make JRootPane be the root of a focus cycle.
  371.      * That means that, by default, tabbing within the root
  372.      * pane will move between components of the pane,
  373.      * but not out of the pane.
  374.  
  375.      * @see JComponent#isFocusCycleRoot
  376.      * @return true
  377.      */
  378.     public boolean isFocusCycleRoot() {
  379.         return true;
  380.     }
  381.  
  382.     /**
  383.      * If a descendant of this JRootPane calls revalidate, validate
  384.      * from here on down.
  385.      *<p>
  386.      * Deferred requests to relayout a component and it's descendants,
  387.      * i.e. calls to revalidate(), are pushed upwards to either a JRootPane 
  388.      * or a JScrollPane because both classes override isValidateRoot() to 
  389.      * return true.
  390.      * 
  391.      * @see JComponent#isValidateRoot
  392.      * @return true
  393.      */
  394.     public boolean isValidateRoot() {
  395.     return true;
  396.     }
  397.  
  398.     /**
  399.      * Register ourselves with the SystemEventQueueUtils as a new
  400.      * root pane. 
  401.      */
  402.     public void addNotify() {
  403.     SystemEventQueueUtilities.addRunnableCanvas(this);
  404.         super.addNotify();
  405.         enableEvents(AWTEvent.KEY_EVENT_MASK);
  406.     }
  407.  
  408.     // Note: These links don't work because the target
  409.     //       class is package private
  410.     // @see SystemEventQueueUtilities#addRunnableCanvas
  411.     // @see SystemEventQueueUtilities#removeRunnableCanvas
  412.  
  413.     /**
  414.      * Unregister ourselves from SystemEventQueueUtils.
  415.      */
  416.     public void removeNotify() {
  417.     SystemEventQueueUtilities.removeRunnableCanvas(this);
  418.         super.removeNotify();
  419.     }
  420.  
  421.  
  422.     /**
  423.      * Sets the current default button for this JRootPane.
  424.      * The default button is the button which will be activated 
  425.      * when a UI-defined activation event (typically the Enter key) 
  426.      * occurs in the RootPane regardless of whether or not the button 
  427.      * has keyboard focus (unless there is another component within 
  428.      * the RootPane which consumes the activation event, such as a JTextPane).
  429.      * For default activation to work, the button must be an enabled
  430.      * descendent of the RootPane when activation occurs.
  431.      * To remove a default button from this RootPane, set this
  432.      * property to null.
  433.      *
  434.      * @see JButton#isDefaultButton 
  435.      * @param default the JButton which is to be the default button
  436.      */
  437.     public void setDefaultButton(JButton defaultButton) { 
  438.         JButton oldDefault = this.defaultButton;
  439.  
  440.         this.defaultButton = defaultButton;
  441.         if (defaultPressAction == null) {
  442.             defaultPressAction = new DefaultAction(this, true);
  443.             defaultReleaseAction = new DefaultAction(this, false);
  444.             // Eventually we should get the KeyStroke from the UI
  445.             // but hardcode it for now....
  446.             registerKeyboardAction(defaultPressAction, 
  447.                                    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), 
  448.                                    JComponent.WHEN_IN_FOCUSED_WINDOW);
  449.             registerKeyboardAction(defaultReleaseAction, 
  450.                                    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), 
  451.                                    JComponent.WHEN_IN_FOCUSED_WINDOW);
  452.         }
  453.         if (oldDefault != defaultButton) {
  454.             defaultPressAction.setOwner(defaultButton);
  455.             defaultReleaseAction.setOwner(defaultButton);
  456.  
  457.             if (oldDefault != null) {
  458.                 oldDefault.repaint();
  459.             }
  460.             if (defaultButton != null) {
  461.                 defaultButton.repaint();
  462.             }
  463.         }
  464.  
  465.         firePropertyChange("defaultButton", oldDefault, defaultButton);        
  466.     }
  467.  
  468.     /**
  469.      * Returns the current default button for this JRootPane.
  470.      * @return the JButton which is currently the default button
  471.      */
  472.     public JButton getDefaultButton() { 
  473.         return defaultButton;
  474.     }
  475.  
  476.     static class DefaultAction extends AbstractAction {
  477.         JButton owner;
  478.         JRootPane root;
  479.         boolean press;
  480.         DefaultAction(JRootPane root, boolean press) {
  481.             super(press? "pressedAction" : "releasedAction");
  482.             this.root = root;
  483.             this.press = press;
  484.         }
  485.         public void setOwner(JButton owner) {
  486.             this.owner = owner;
  487.         }
  488.         public void actionPerformed(ActionEvent e) {
  489.             if (owner != null && SwingUtilities.getRootPane(owner) == root) {
  490.                 ButtonModel model = owner.getModel();
  491.                 if (press) {
  492.                     model.setArmed(true);
  493.                     model.setPressed(true);
  494.                 } else {
  495.                     model.setPressed(false);
  496.                 }
  497.             }
  498.         }
  499.         public boolean isEnabled() {
  500.             return owner.getModel().isEnabled();
  501.         }
  502.     }
  503.  
  504.  
  505.     /** Overridden to enforce the position of the glass component as the zero child. */
  506.     protected void addImpl(Component comp, Object constraints, int index) {
  507.         super.addImpl(comp, constraints, index);
  508.         
  509.         /// We are making sure the glassPane is on top. 
  510.         if(glassPane != null 
  511.             && glassPane.getParent() == this
  512.             && getComponent(0) != glassPane) {
  513.             add(glassPane, 0);
  514.         }
  515.     }
  516.  
  517. ///////////////////////////////////////////////////////////////////////////////
  518. //// Begin Inner Classes
  519. ///////////////////////////////////////////////////////////////////////////////
  520.  
  521.  
  522.     /** 
  523.      * A custom layout manager that is responsible for the layout of 
  524.      * layeredPane, glassPane, and menuBar.
  525.      * <p>
  526.      * <strong>Warning:</strong>
  527.      * Serialized objects of this class will not be compatible with
  528.      * future Swing releases.  The current serialization support is appropriate
  529.      * for short term storage or RMI between applications running the same
  530.      * version of Swing.  A future release of Swing will provide support for
  531.      * long term persistence.
  532.      */
  533.     protected class RootLayout implements LayoutManager2, Serializable
  534.     {
  535.         /**
  536.          * Returns the amount of space the layout would like to have.
  537.          *
  538.          * @param the Container for which this layout manager is being used
  539.          * @return a Dimension object containing the layout's preferred size
  540.          */ 
  541.         public Dimension preferredLayoutSize(Container parent) {
  542.             Dimension rd, mbd;
  543.             Insets i = getInsets();
  544.         
  545.             if(contentPane != null) {
  546.                 rd = contentPane.getPreferredSize();
  547.             } else {
  548.                 rd = parent.getSize();
  549.             }
  550.             if(menuBar != null) {
  551.                 mbd = menuBar.getPreferredSize();
  552.             } else {
  553.                 mbd = new Dimension(0, 0);
  554.             }
  555.             return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right, 
  556.                                         rd.height + mbd.height + i.top + i.bottom);
  557.         }
  558.  
  559.         /**
  560.          * Returns the minimum amount of space the layout needs.
  561.          *
  562.          * @param the Container for which this layout manager is being used
  563.          * @return a Dimension object containing the layout's minimum size
  564.          */ 
  565.         public Dimension minimumLayoutSize(Container parent) {
  566.             Dimension rd, mbd;
  567.             Insets i = getInsets();
  568.             if(contentPane != null) {
  569.                 rd = contentPane.getMinimumSize();
  570.             } else {
  571.                 rd = parent.getSize();
  572.             }
  573.             if(menuBar != null) {
  574.                 mbd = menuBar.getMinimumSize();
  575.             } else {
  576.                 mbd = new Dimension(0, 0);
  577.             }
  578.             return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right, 
  579.                         rd.height + mbd.height + i.top + i.bottom);
  580.         }
  581.  
  582.         /**
  583.          * Returns the maximum amount of space the layout can use.
  584.          *
  585.          * @param the Container for which this layout manager is being used
  586.          * @return a Dimension object containing the layout's maximum size
  587.          */ 
  588.         public Dimension maximumLayoutSize(Container target) {
  589.             Dimension rd, mbd;
  590.             Insets i = getInsets();
  591.             if(menuBar != null) {
  592.                 mbd = menuBar.getMaximumSize();
  593.             } else {
  594.                 mbd = new Dimension(0, 0);
  595.             }
  596.             if(contentPane != null) {
  597.                 rd = contentPane.getMaximumSize();
  598.             } else {
  599.                 // This is silly, but should stop an overflow error
  600.                 rd = new Dimension(Integer.MAX_VALUE, 
  601.                         Integer.MAX_VALUE - i.top - i.bottom - mbd.height - 1);
  602.             }
  603.             return new Dimension(Math.min(rd.width, mbd.width) + i.left + i.right,
  604.                                          rd.height + mbd.height + i.top + i.bottom);
  605.         }
  606.         
  607.         /**
  608.          * Instructs the layout manager to perform the layout for the specified
  609.          * container.
  610.          *
  611.          * @param the Container for which this layout manager is being used
  612.          */ 
  613.         public void layoutContainer(Container parent) {
  614.             Rectangle b = parent.getBounds();
  615.             Insets i = getInsets();
  616.             int contentY = 0;
  617.             int w = b.width - i.right - i.left;
  618.             int h = b.height - i.top - i.bottom;
  619.         
  620.             if(layeredPane != null) {
  621.                 layeredPane.setBounds(i.left, i.top, w, h);
  622.             }
  623.             if(glassPane != null) {
  624.                 glassPane.setBounds(i.left, i.top, w, h);
  625.             }
  626.             // Note: This is laying out the children in the layeredPane,
  627.             // technically, these are not our chilren.
  628.             if(menuBar != null) {
  629.                 Dimension mbd = menuBar.getPreferredSize();
  630.                 menuBar.setBounds(0, 0, w, mbd.height);
  631.                 contentY += mbd.height;
  632.             }
  633.             if(contentPane != null) {
  634.                 contentPane.setBounds(0, contentY, w, h - contentY);
  635.             }
  636.         }
  637.         
  638.         public void addLayoutComponent(String name, Component comp) {}
  639.         public void removeLayoutComponent(Component comp) {}
  640.         public void addLayoutComponent(Component comp, Object constraints) {}
  641.         public float getLayoutAlignmentX(Container target) { return 0.0f; }
  642.         public float getLayoutAlignmentY(Container target) { return 0.0f; }
  643.         public void invalidateLayout(Container target) {}
  644.     }
  645.  
  646.  
  647.     /**
  648.      * Returns a string representation of this JRootPane. This method 
  649.      * is intended to be used only for debugging purposes, and the 
  650.      * content and format of the returned string may vary between      
  651.      * implementations. The returned string may be empty but may not 
  652.      * be <code>null</code>.
  653.      * <P>
  654.      * Overriding paramString() to provide information about the
  655.      * specific new aspects of the JFC components.
  656.      * 
  657.      * @return  a string representation of this JRootPane.
  658.      */
  659.     protected String paramString() {
  660.     return super.paramString();
  661.     }
  662.  
  663. /////////////////
  664. // Accessibility support
  665. ////////////////
  666.  
  667.     /**
  668.      * Get the AccessibleContext associated with this JComponent
  669.      *
  670.      * @return the AccessibleContext of this JComponent
  671.      */
  672.     public AccessibleContext getAccessibleContext() {
  673.         if (accessibleContext == null) {
  674.             accessibleContext = new AccessibleJRootPane();
  675.         }
  676.         return accessibleContext;
  677.     }
  678.  
  679.     /**
  680.      * The class used to obtain the accessible role for this object.
  681.      * <p>
  682.      * <strong>Warning:</strong>
  683.      * Serialized objects of this class will not be compatible with
  684.      * future Swing releases.  The current serialization support is appropriate
  685.      * for short term storage or RMI between applications running the same
  686.      * version of Swing.  A future release of Swing will provide support for
  687.      * long term persistence.
  688.      */
  689.     protected class AccessibleJRootPane extends AccessibleJComponent {
  690.         /**
  691.          * Get the role of this object.
  692.          *
  693.          * @return an instance of AccessibleRole describing the role of 
  694.          * the object
  695.          */
  696.         public AccessibleRole getAccessibleRole() {
  697.             return AccessibleRole.ROOT_PANE;
  698.         }
  699.     } // inner class AccessibleJRootPane
  700.  
  701. }
  702.